package gui

import (
	"fmt"

	"fyne.io/fyne/v2/widget"
)

/*var cpu = widget.NewMultiLineEntry()
var cpubutton = widget.NewButton("获取cpu信息", func() {
	cpu.SetText("")
	t, err := info.MpaCPUInfo()
	if err != nil {
		cpu.SetText("err")
		return
	}
	for k, v := range t {
		cpu.Append(fmt.Sprintf("==>第%d个CPU信息:\n", k+1))
		for kd, kv := range v {
			cpu.Append(fmt.Sprintf("%v:%v\n", kd, kv))
		}

	}

})

*/

//MapBaseBoardInfo

type hardware struct {
	Entry    *widget.Entry
	Btn      *widget.Button
	Btnname  string
	hardName string
	InfoFunc func() ([]map[string]interface{}, error)
	//Btnfn    func(entry *widget.Entry, hardName string)
}

func NewHardware(btnnam, hardName string, infofn func() ([]map[string]interface{}, error)) hardware {
	return hardware{Entry: widget.NewMultiLineEntry(), Btn: &widget.Button{}, Btnname: btnnam, hardName: hardName, InfoFunc: infofn}
}

func (h *hardware) Btnfn() *widget.Button {
	h.Btn.SetText(h.Btnname)
	h.Btn.OnTapped = func() {

		h.Entry.SetText("")
		t, err := h.InfoFunc()
		if err != nil {
			h.Entry.SetText("err")
			return
		}
		for k, v := range t {
			h.Entry.Append(fmt.Sprintf("========>第%d条%s信息:<========\n", k+1, h.hardName))
			for kd, kv := range v {
				h.Entry.Append(fmt.Sprintf("%v:%+v\n", kd, kv))
			}

		}
	}
	return h.Btn

}
